package com.shujia.spark.mllib

import org.apache.spark.ml.feature.LabeledPoint
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors

object Demo1Vector {
  def main(args: Array[String]): Unit = {

    /**
      * 稠密向量
      *
      */

    val vector: linalg.Vector = Vectors.dense(1.0, 2.3, 4.0, 2.4, 2.4)

    println(vector)

    /**
      * 稀疏向量
      *
      * 只保存有值的位置，0位置不保存
      *
      */

    val v1: linalg.Vector = Vectors.sparse(10, Array(1, 3, 4), Array(1.2, 4.5, 6.7))

    println(v1)

    //相互转换
    println(v1.toDense)

    /**
      * LabeledPoint代表一条训练数据，
      *
      */

    val pos = LabeledPoint(1.0, Vectors.dense(1.0, 0.0, 3.0))

    // Create a labeled point with a negative label and a sparse feature vector.
    val neg = LabeledPoint(0.0, Vectors.sparse(3, Array(0, 2), Array(1.0, 3.0)))

  }
}
